


import 'package:dio/dio.dart';

import 'HttpManager.dart';

class Api{
  static final baseUrl = "https://www.wanandroid.com/";

  //文章
  static final ARTICLE_LIST = "article/list/";

  //banner
  static final BANNER = "banner/json";

  //登录
  static const String LOGIN = "user/login";

  //注册
  static const String REGISTER = "user/register";

  //退出
  static const String LOGOUT = "user/logout/json";

  //收藏文章列表
  static const String COLLECT_ARTICLE_LIST = "lg/collect/list";

  //收藏网站列表
  static const String COLLECT_WEBSITE_LIST = "lg/collect/usertools/json";

  //删除收藏网站
  static const String UNCOLLECT_WEBSITE = "lg/collect/deletetool/json";

  static final HttpManager httpManager = HttpManager.getInstance();

  static getArticleCollects(int page) async {
    return await httpManager.request("$COLLECT_ARTICLE_LIST/$page/json");
  }

  static getArticle(url) async{
    return await httpManager.request(url);
  }

  static getWebSiteCollects() async {
    return await httpManager.request(COLLECT_WEBSITE_LIST);
  }

  static getArticleList(int page) async {
    return await httpManager.request('$ARTICLE_LIST$page/json');
  }

  static getBanners() async {
    return await httpManager.request(BANNER);
  }

  static login(String username, String password) async {
    var formData = FormData.fromMap({
      "username": username,
      "password": password,
    });
    return await httpManager.request(LOGIN,data: formData, method: "post");
  }

  static register(String username, String password) async {
    var formData = FormData.fromMap(
        {"username": username, "password": password, "repassword": password});
    return await httpManager.request(REGISTER, data: formData, method: "post");
  }

  static clearCookie() {
    httpManager.clearCookie();
  }

  static init() async {
    await httpManager.init();
  }

  static unCollectWebsite(int id) async {
    var formData = FormData.fromMap({"id": id});
    return await httpManager
        .request(UNCOLLECT_WEBSITE, data: formData, method: "post");
  }


}